package cn.pugle.base.thread.ticketlock;

import java.util.WeakHashMap;

/**
 * CacheBuilder.newBuilder().weakKeys();
 * @author tzp
 * @since 2018/7/9
 */
public class TicketLock5 {
    WeakHashMap<Long, Long> locks = new WeakHashMap<>();

    public Object getLock(Long ticketNumber) {
        synchronized (locks) {
            locks.putIfAbsent(ticketNumber, ticketNumber);
            return locks.get(ticketNumber);
        }
    }
}